<script setup lang="ts">
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { storeToRefs } from 'pinia'
import { useHospitalStore } from '@/store/modules/hospital'
import { useChangeLoginBoxStatus } from '@/hooks/useLoginShow'

const $router = useRouter()
const $route = useRoute()

const useHospital = useHospitalStore()
const { registerData, departmentData } = storeToRefs(useHospital)
// show step
const isStep = ref<boolean>(false)
const popLoginBox = (item: any) => {
  // useChangeLoginBoxStatus()
  // 路由鉴权
  isStep.value = true
  // 选择科室 => 进入 【预约挂号】1 ：选择挂号时间 => 进入 【预约挂号】2: =》确认挂号信息 页
  console.log(item)
  $router.push({
    path: $route.path + `/step1`,
    query: {
      hoscode: $route.query.hoscode,
      depcode: item.depcode
    }
  })
}
</script>
<template>
  <div class="hospital-register">
    <template v-if="!isStep">
      <!-- title : 北京人民医院 icon 三级甲等-->
      <div class="titlebox">
        <custom-title-v2
          class="name"
          :title="registerData?.hospital?.hosname"
        ></custom-title-v2>
        <hospital-level
          :levelName="registerData.hospital?.param.hostypeString"
        ></hospital-level>
      </div>
      <!-- 简介：左：logo 右：挂号规则 医院预约规则 -->
      <div class="introbox">
        <div class="logo">
          <img
            class="logo-img"
            :src="`data:image/jpeg;base64,${registerData.hospital?.logoData}`"
            alt=""
          />
          <!-- <img class="logo-img" src="../../../assets/images/logo.png" alt="" /> -->
        </div>
        <div class="intro-info">
          <div class="intro-rule">
            <div class="rule-title">挂号规则</div>
            <div class="rule-v1">
              <div class="rule">
                <div class="rule-ltitle">预约周期:</div>
                <div class="rule-text">
                  {{ registerData.bookingRule?.cycle }}天
                </div>
              </div>
              <div class="rule">
                <div class="rule-ltitle">放号时间:</div>
                <div class="rule-text">
                  {{ registerData.bookingRule?.releaseTime }}天
                </div>
              </div>
              <div class="rule">
                <div class="rule-ltitle">停止挂号时间:</div>
                <div class="rule-text">
                  {{ registerData.bookingRule?.stopTime }}天
                </div>
              </div>
            </div>
            <div class="rule-v1">
              <div class="rule">
                <div class="rule-ltitle">退号时间:</div>
                <div class="rule-text">
                  就诊前一工作日{{ registerData.bookingRule?.quitTime }}前取消
                </div>
              </div>
            </div>
          </div>
          <div class="intro-rule">
            <div class="rule-title">医院预约规则</div>
            <div class="rule-v2">
              <ul class="rule-list">
                <li v-for="item in registerData.bookingRule?.rule" :key="item">
                  {{ item }}
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
      <!-- 选择科室 -->
      <div class="class-room">
        <!-- title -->
        <custom-title-v1 title="选择科室"></custom-title-v1>
        <el-tabs type="border-card" tab-position="left" class="hos-tabs">
          <template v-for="item in departmentData" :key="item.depcode">
            <el-tab-pane :label="item.depname">
              <div class="room-list">
                <custom-title-v3 :title="item.depname"></custom-title-v3>
                <div class="rooms">
                  <template v-if="item?.children">
                    <span
                      class="text"
                      v-for="itemChild in item.children"
                      :key="itemChild.depcode"
                      @click="popLoginBox(itemChild)"
                      >{{ itemChild.depname }}</span
                    >
                  </template>
                </div>
              </div>
            </el-tab-pane>
          </template>
        </el-tabs>
      </div>
    </template>
    <template v-if="isStep">
      <!-- <div class="step-view">
        <el-breadcrumb separator="|">
          <el-breadcrumb-item
            :to="{
              path: `/hospital/register?hoscode=${$route.query.hoscode}`
            }"
          >
            {{ registerData?.hospital?.hosname }}
          </el-breadcrumb-item>
        </el-breadcrumb>
      </div> -->
      <router-view></router-view>
    </template>
  </div>
</template>
<style scoped lang="less">
.hospital-register {
  padding: 20px;
  .titlebox {
    display: flex;
    align-items: center;
    .name {
      margin-right: 20px;
    }
  }
  .introbox {
    display: flex;
    padding: 20px 0;

    .logo {
      width: 150px;
      text-align: center;
      padding: 15px 0;
      .logo-img {
        width: 80px;
        height: 80px;
        border-radius: 40px;
      }
    }
    .intro-info {
      flex: 1;
      .intro-rule {
        .rule-title {
          font-size: 16px;
          color: #333;
          margin: 15px 0;
        }
        .rule-v1,
        .rule-v2 {
          font-size: 12px;
          line-height: 25px;
        }

        .rule-v1 {
          display: flex;
          align-items: center;
          justify-content: space-between;
          .rule {
            flex: 1;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
          }
          .rule-ltitle {
            color: #999;
          }
          .rule-text {
            color: #333;
            padding-left: 10px;
          }
        }
        .rule-v2 {
          color: #999;
          ul.rule-list {
            list-style: decimal;
            padding-left: 20px;
          }
        }
      }
    }
  }
  .class-room {
    margin-top: 20px;
    :deep(.el-tabs--border-card) {
      border: 1px solid #f8f8f8;
      .el-tabs__header {
        background: #f4f9ff;
        border-bottom: none;
      }
      .el-tabs__item,
      .is-left {
        border: none;
      }
      .el-tabs__item {
        color: #333;
        text-align: center;
        height: 45px;
        line-height: 45px;
        width: 100%;
      }
      .is-left {
        justify-content: center;
        // padding: 10px 0;
      }
      .is-active {
        font-size: 16px;
        font-weight: 700;
        border: none;
        width: 100%;
        align-items: center;
      }
      .el-tabs__nav {
        width: 170px;
        display: flex;
        align-items: center;
        padding: 0;
      }
    }

    .hos-tabs {
      background: #fafafa;
    }
    .room-list {
      font-size: 14px;
      .rooms {
        display: flex;
        margin: 20px 15px;
        flex-wrap: wrap;
        align-items: center;
        justify-items: flex-start;

        span.text {
          cursor: pointer;
          color: #666;
          width: 33.3%;
          line-height: 35px;
          &:hover {
            color: var(--second-color);
          }
        }
      }
    }
  }

  // step
  .step-view {
  }
}
</style>
